<?php

require_once 'Pipes/Config.php';
require_once 'Pipes/View.php';
require_once 'PipesImpl/FileSystem/Directory.php';

class Pipes_Generator_Start_Index
{
	private $_projectPath = null;
	private $_view = null;

	public function __construct(PipesImpl_FileSystem_Directory $root) {
		$this->_projectPath = $root;

		$config = new Pipes_Config(array('projects' => array('PipesCore')));
		$this->_view = new Pipes_View($config, 'GeneratorTemplates');
		$this->_view->project = basename($this->_projectPath->toString());
		$this->_view->projectIncludePath = dirname($this->_projectPath->toString());
		$this->_view->generatingClass = __CLASS__;
		$this->_view->pathToPipes = realpath(dirname(__FILE__) . '/../../../');
	}

	public function create() {
		$filename = $this->_projectPath->toString() . DIRECTORY_SEPARATOR . 'Public' . DIRECTORY_SEPARATOR . 'index.php';

		$fp = fopen($filename, 'x+');
		fwrite($fp, str_replace('<\?php', '<?php', $this->_view->render('public/index')));
		fclose($fp);
	}
}
